<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>33.1-图书案例-数组方法</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style></style>
  </head>
  <body>
    <div id="app">
      <div>
        <input type="text" v-model="name" />
        <button @click="add">添加</button>
        <button @click="del">删除</button>
        <button @click="change">替换</button>
      </div>
      <ul>
        <li v-for="(item, index) in list" :key="index">{{item}}</li>
      </ul>
    </div>
    <script>
      var vm = new Vue({
        el: '#app',
        data: {
          nmae: '',
          list: ['apple', 'banana', 'orange'],
        },
        methods: {
          add: function () {
            this.list.push(this.name);
          },
          del: function () {
            this.list.pop();
          },
          change: function () {
            this.list = this.list.slice(0, 2);
          },
        },
      });
    </script>
  </body>
</html>
